package com.sky.web.servlet;

import java.util.ArrayList;
import java.util.List;
import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sky.domain.User;
import com.sky.service.UserService;
import com.sky.utils.PassWordutil;

public class QueryUserListServlet extends HttpServlet {



	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //业务逻辑，查询数据库表中所有的用户
		UserService userService =new UserService();
		try {
			List<User> 	list = userService.queryUserList();
			System.out.println("==QueryUserListServlet==="+list.size());
			//把所有用户集合交给showuserlist.jsp进行显示
			//============================
			try{
			List<String> pwd=new ArrayList<String>();
			for(int i=0;i<list.size();i++){
				PassWordutil des1 = new PassWordutil();
				String pwdString=des1.decrypt(list.get(i).getPassword());
				list.get(i).setPassword(pwdString);
			}
			request.setAttribute("pwdlist", pwd);
			}catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
			}
			//============================
			request.setAttribute("list", list);
			request.getRequestDispatcher("home/showuserlist.jsp").forward(request, response);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

	

}
